<?php
namespace Wx\Controller;
use Think\Controller;

class VipController extends CommonController{
	//会员特权
	public function membership(){
		$s_id=$_GET['s_id'];//门店id
		if($s_id>0){
			//会员等级
			$member=D('member');
			$growth=$member->where("id=".session('u_id'))->getField('growth');
			if($growth<1000){$growth=1;$need=1000-$growth;}
			if($growth>=1000 and $growth<3000){$growth=2;$need=3000-$growth;}
			if($growth>=3000 and $growth<6000){$growth=3;$need=6000-$growth;}
			if($growth>=6000){$growth=4;}
			$this->assign('growth',$growth);
			$this->assign('need',$need);
			//社区店铺兑换-会员专享
			$exchange_goods=D('exchange_goods');
			$shop_store=D('shop_store');
			$category=D('category');
			$shopinfo=$shop_store->where("id=".$s_id)->find();
			$s_u_id=$shopinfo['u_id'];
			$where="";
			if($s_u_id>0)$where=" or u_id=".$s_u_id;
			$goods=$exchange_goods->where("u_id=0".$where)->select();//品牌类型兑换产品
			$goods_1='';//普通
			$goods_2='';//黄金
			$goods_3='';//白金
			$goods_4='';//砖石
			foreach($goods as $i=>$one){
				//u_id=0的判断本店是否在授权范围内
				$c_id_arr=explode(',',$one['c_id_str']);
				if(($one['u_id']==0 && in_array($shopinfo['c_id'],$c_id_arr))||$one['u_id']>0){
					//本小区在该品牌兑换内|兑换是本社区发布 
				}else{
					continue;
				}//end if
					//产品第一图片 
					$img=explode(',',$one['head_img']);
					$goods[$i]['f_img']=$img[0];//第一张图片作为封面图
					//查商品单位
					$getc=$category->where("id=".$one['unit'])->find();
					$goods[$i]['unit']=$getc['title'];
				if($one['level_cash_1']==0 and $one['level_cash_2']==0 and $one['level_cash_3']==0 and 
					$one['level_integral_1']==0 and $one['level_integral_2']==0 and $one['level_integral_3']==0 and 
					($one['level_cash_4']>0 or $one['level_integral_4']>0))$goods_4[]=$goods[$i];
				if($one['level_cash_1']==0 and $one['level_cash_2']==0 and $one['level_cash_4']==0 and 
					$one['level_integral_1']==0 and $one['level_integral_2']==0 and $one['level_integral_4']==0 and 
					($one['level_cash_3']>0 or $one['level_integral_3']>0))$goods_3[]=$goods[$i];
				if($one['level_cash_1']==0 and $one['level_cash_4']==0 and $one['level_cash_3']==0 and 
					$one['level_integral_1']==0 and $one['level_integral_4']==0 and $one['level_integral_3']==0 and 
					($one['level_cash_2']>0 or $one['level_integral_2']>0))$goods_2[]=$goods[$i];
				if($one['level_cash_4']==0 and $one['level_cash_2']==0 and $one['level_cash_3']==0 and 
					$one['level_integral_4']==0 and $one['level_integral_2']==0 and $one['level_integral_3']==0 and 
					($one['level_cash_1']>0 or $one['level_integral_1']>0))$goods_1[]=$goods[$i];
			}//end foreach
			$this->assign('goods_1',$goods_1);
			$this->assign('goods_2',$goods_2);
			$this->assign('goods_3',$goods_3);
			$this->assign('goods_4',$goods_4);

			$this->display();
		}else{
			$this->error('非法操作！','/Wx/Index/',2);
		}//end if
	}//end fun
}//end class